using System;

namespace SpecMaker.Core.Dsl
{
    public class SpecDescription
    {
        private readonly Spec _spec;
        private readonly Type _type;

        public SpecDescription(Spec spec, Type type)
        {
            _spec = spec;
            _type = type;
        }

        public SpecContext WithContext(string desc, params SetupTeardown[] actions)
        {

            _spec.Description = desc;
            _spec.TypeUnderDescription = _type;
            SpecContext context = new SpecContext(_spec);
            foreach (var action in actions)
            {
                if (action.GetType() == typeof(BeforeEachRule))
                    _spec.BeforeEachRuleMethod = action as BeforeEachRule;
                else if (action.GetType() == typeof(BeforeSpec))
                    _spec.BeforeSpecMethod = action as BeforeSpec;
                else if (action.GetType() == typeof(AfterEachRule))
                    _spec.AfterEachMethod = action as AfterEachRule;
                else if (action.GetType() == typeof(AfterSpec))
                    _spec.AfterSpecMethod = action as AfterSpec;
            }
            return context;

        }
    }
}